const mongoose = require('mongoose');
const { ClassifysModel } = require('../index');

// 连接数据库
mongoose.connect('mongodb+srv://2334231668:xin123666@cluster0.13va5ah.mongodb.net/2409B', {
  useNewUrlParser: true,
  useUnifiedTopology: true,
});

// 分类数据
const classifys = [
  { name: '时令水果' },
  { name: '新鲜蔬菜' },
  { name: '肉禽蛋类' },
  { name: '海鲜水产' },
  { name: '粮油调味' },
  { name: '乳品烘焙' },
  { name: '时令果蔬' }
];

async function insertClassifyData() {
  try {
    // 清空现有数据
    await ClassifysModel.deleteMany({});
    console.log('已清空现有分类数据');

    // 插入新数据
    const result = await ClassifysModel.insertMany(classifys);
    console.log('分类数据插入成功:', result.length, '条记录');

    // 查询验证
    const allClassifys = await ClassifysModel.find({});
    console.log('当前所有分类:', allClassifys);

  } catch (error) {
    console.error('插入分类数据失败:', error);
  } finally {
    mongoose.connection.close();
    console.log('数据库连接已关闭');
  }
}

insertClassifyData(); 